package com.wang.web3.weight;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wang.web3.R;

/**
 * Created by SAR on 2018/4/9.
 */

public class KittyWindow extends DialogFragment implements View.OnClickListener{


    TextView tv_gril_info1,tv_gril_info2,tv_gril_info3;
    ImageView iv_kittyframe,iv_kittywing;
    LinearLayout mlin1,mlin2;
    Button mBtnVestWings,mBtnCancleKitty,mBtnSaleKitty;

    KittyWindowOnClick kitttyWindowOnClick;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.kitty_info_dialog, container, false);
        tv_gril_info1 = v.findViewById(R.id.tv_gril_info1);
        tv_gril_info2 = v.findViewById(R.id.tv_gril_info2);
        tv_gril_info3 = v.findViewById(R.id.tv_gril_info3);
        mBtnVestWings = v.findViewById(R.id.mBtnVestWings);
        iv_kittyframe = v.findViewById(R.id.iv_kittyframe);
        iv_kittywing = v.findViewById(R.id.iv_kittywings);
        mlin1 = v.findViewById(R.id.mlin1);
        mlin2 = v.findViewById(R.id.mlin2);
        mBtnVestWings.setOnClickListener(this);
        v.findViewById(R.id.mBtnVestPhotoFrame).setOnClickListener(this);
        v.findViewById(R.id.mBtnResolveKitty).setOnClickListener(this);
        v.findViewById(R.id.mBtnBackKitty).setOnClickListener(this);
        mBtnSaleKitty = v.findViewById(R.id.mBtnSaleKitty);
        mBtnSaleKitty.setOnClickListener(this);
        v.findViewById(R.id.mBtnBuyKitty).setOnClickListener(this);
        mBtnCancleKitty = v.findViewById(R.id.mBtnCancleKitty);
        mBtnCancleKitty.setOnClickListener(this);
        Bundle bundle  = getArguments();
         String kittyInfo1 = bundle.getString("kittyInfo1");
         String kittyInfo2 = bundle.getString("kittyInfo2");
         String kittyInfo3 = bundle.getString("kittyInfo3");
        tv_gril_info1.setText(kittyInfo1);
        tv_gril_info2.setText(kittyInfo2);
        tv_gril_info3.setText(kittyInfo3);
        int aaa = kittyInfo3.indexOf("wingType:1");
        if (kittyInfo3.indexOf("wingType:1") != -1){
            iv_kittywing.setVisibility(View.VISIBLE);
        }

        if (kittyInfo3.indexOf("photoFrameType:1") != -1){
            iv_kittyframe.setVisibility(View.VISIBLE);
        }

        if (kittyInfo3.indexOf("market") != -1){
            mlin1.setVisibility(View.GONE);
            mlin2.setVisibility(View.GONE);
            mBtnSaleKitty.setVisibility(View.GONE);
            mBtnCancleKitty.setVisibility(View.VISIBLE);
        }

        return v;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public void onStart()
    {
        super.onStart();
        DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics( dm );
        getDialog().getWindow().setLayout( dm.widthPixels, getDialog().getWindow().getAttributes().height );
    }

    public void haveProps(boolean wings,boolean photoframe){
        if (photoframe){
            iv_kittyframe.setVisibility(View.VISIBLE);
        }else{
            iv_kittyframe.setVisibility(View.GONE);
        }
        if (wings){
            iv_kittywing.setVisibility(View.VISIBLE);
        }else{
            iv_kittywing.setVisibility(View.GONE);
        }
    }
    public void initOnClick(final KittyWindowOnClick kitttyWindowOnClick){
        this.kitttyWindowOnClick = kitttyWindowOnClick;
    }

    public void upDateInfo(String kittyInfo1,String kittyInfo2,String kittyInfo3){
        tv_gril_info1.setText(kittyInfo1);
        tv_gril_info2.setText(kittyInfo2);
        tv_gril_info3.setText(kittyInfo3);
    }

    public static KittyWindow showKitty(FragmentManager fragmentManager,String kittyInfo1,String kittyInfo2,String kittyInfo3) {
        KittyWindow kittyWindow = new KittyWindow();
        Bundle bundle = new Bundle();
        bundle.putString("kittyInfo1", kittyInfo1);
        bundle.putString("kittyInfo2", kittyInfo2);
        bundle.putString("kittyInfo3", kittyInfo3);
        kittyWindow.setArguments(bundle);
        kittyWindow.show(fragmentManager, "kittyWindow");
        return  kittyWindow;
    }

    @Override
    public void onClick(View v) {
        kitttyWindowOnClick.onClick(v);
    }

    public interface KittyWindowOnClick{
        void onClick(View v);
    }
}
